package com.software.lineragent.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.software.common.CommonUtils;
import com.software.form.bookingform.dao.BookingForm;
import com.software.form.bookingform.dao.BookingFormTransaction;
import com.software.form.interchangeform.dao.InterchangeFormTransaction;

public class InterchangeServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		InterchangeFormTransaction ift = (InterchangeFormTransaction) CommonUtils.getBean("interchangeFormTransaction");
		JSONObject json = CommonUtils.readJSONStringFromRequestBody(request, response);
		try{
			String company = json.getString("company");
			String no = json.getString("no");
			String user = json.getString("user");
			String pod = json.getString("pod");
			String dt = json.getString("dt");
			String por = json.getString("por");
			String vess = json.getString("vess");
			String cno = json.getString("cno");
			String size = json.getString("size");
			String optr = json.getString("optr");
			String seal = json.getString("seal");
			String truck = json.getString("truck");
			String pout = json.getString("pout");
			String pin = json.getString("pin");
			String timeout = json.getString("timeout");
			String sagentEmail = json.getString("sagentEmail");
			
			boolean tag  = false;
			tag = ift.add(company, no, user, pod, dt, por, vess, cno, size, optr, seal, truck, pout, pin, timeout,sagentEmail,null);
			if(tag){
				CommonUtils.outputJsonData(1, response);
			}else{
				CommonUtils.outputJsonData(0, response);
			}
		}catch(JSONException je){
			try {
				CommonUtils.outputJsonData(0, response);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
